<#escape x as (x)!"">
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
 PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="${basePackage}.${platPackage}.${modulePackage}.dao.${className}Dao">

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="${basePackage}.entity.${modulePackage}.${className}Entity" id="${classname}Map">
	<#if columns??>
		<#list columns as column>
		<result property="${column.attrname}" column="${column.columnName}"/>
		</#list>
	</#if>
    
    </resultMap>

	<select id="queryObject" resultType="${basePackage}.entity.${modulePackage}.${className}Entity">
		select * from ${tableName} where ${pk.columnName} = ${r"#{value}"};
	</select>
	
	<select id="queryList" resultType="${basePackage}.entity.${modulePackage}.${className}Entity">
		select * from ${tableName}
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by ${pk.columnName} desc
			</otherwise>
        </choose>
	</select>

	<select id="queryList" resultType="${basePackage}.entity.${modulePackage}.${className}Entity">
		select * from ${tableName}
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by ${pk.columnName} desc
			</otherwise>
        </choose>
	</select>

	<select id="queryPageList" resultType="${basePackage}.entity.${modulePackage}.${className}Entity">
		select * from ${tableName}
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by ${pk.columnName} desc
			</otherwise>
        </choose>
	</select>

 	<select id="queryTotal" resultType="int">
		select count(*) from ${tableName} 
	</select>


<insert id="save" parameterType="${basePackage}.entity.${modulePackage}.${className}Entity">

<#if (column.isPkey==true && pk.dataType == "NUMBER")>
    		<selectKey keyProperty="${pk.attrname}" resultType="long" order="BEFORE">  
    			select SEQ_${tableName}_ID.NEXTVAL from dual  
    		</selectKey>  
</#if>
		insert into ${tableName}
		(
	<#if columns??>
		<#list columns as column>
		    <#if (column.isPkey==false && pk.extra != 'auto_increment')>
			${column.columnName}<#if column_has_next>,</#if>
			</#if>
		</#list>
	</#if>
		)
		values
		(
	<#if columns??>
		<#list columns as column>
			<#if (column.isPkey==false && pk.extra != 'auto_increment')>
				<#if (column.isPkey==true && pk.dataType == "NUMBER")>
				 ${r"$"}{${column.attrname}}  <#if column_has_next>,</#if>
				<#else>
				${r'#{'}${column.attrname}, ${column.jdbcType}}<#if column_has_next>,</#if> 
				</#if>
			
			</#if>
		</#list>
	</#if>
		)
	</insert>
	 
	<update id="update" parameterType="${basePackage}.entity.${modulePackage}.${className}Entity">
		update ${tableName} 
		<set>
	<#if columns??>
		<#list columns as column>
			<#if test="column.isPkey==false" >
			${column.columnName} = ${r'#{'}${column.attrname}${r'}'} <#if column_has_next>,</#if>
			</#if>
		</#list>
	</#if>
		</set>
		where ${pk.columnName} = ${r'#{'}${pk.attrname}}
	</update>
	
	<delete id="delete">
		delete from ${tableName} where ${pk.columnName} = ${r'#{'}value}
	</delete>
	
	<delete id="deleteBatch">
		delete from ${tableName} where ${pk.columnName} in 
		<foreach item="${pk.attrname}" collection="array" open="(" separator="," close=")">
			${r'#{'}${pk.attrname}}
		</foreach>
	</delete>
</mapper>
</#escape>